home *** CD-ROM | disk | FTP | other *** search
/ Programming a Multiplayer FPS in DirectX / Programming a Multiplayer FPS in DirectX (Companion CD).iso / DirectX / dxsdk_oct2004.exe / dxsdk.exe / Samples / C++ / Direct3D / ConfigSystem / configdatabase.h < prev    next >
Encoding:
C/C++ Source or Header  |  2004-09-28  |  7.7 KB  |  212 lines

  1. //--------------------------------------------------------------------------------------
  2. // File: ConfigDatabase.h
  3. //
  4. // Header file for configuration database object.
  5. //
  6. // Copyright (c) Microsoft Corporation. All rights reserved.
  7. //--------------------------------------------------------------------------------------
  8. #pragma once
  9. #ifndef __CONFIGDATABASE_H__
  10. #define __CONFIGDATABASE_H__
  11.  
  12. #include <d3d9.h>
  13.  
  14. //
  15. // Comment out the following line to remove STL dependencies from this header.
  16. //
  17. #define ICONFIGDATABASE_USE_STL
  18. #ifdef ICONFIGDATABASE_USE_STL
  19.  
  20. //
  21. // STL headers
  22. //
  23. #include <string>
  24. #include <vector>
  25. #include <utility>
  26.  
  27. //
  28. // Typedef for pair of strings
  29. //
  30. typedef std::pair<std::string, std::string> StringPair;
  31.  
  32. #endif // ICONFIGDATABASE_USE_STL
  33.  
  34.  
  35. typedef struct
  36. {
  37.     WCHAR name[64];
  38.     DWORD DriverVersionLowPart;
  39.     DWORD DriverVersionHighPart;
  40.     DWORD VendorID;
  41.     DWORD DeviceID;
  42.     DWORD SubSysID;
  43.     DWORD Revision;
  44. } SOUND_DEVICE;
  45.  
  46.  
  47. HRESULT InitSoundInformation( REFGUID DsoundGuid, SOUND_DEVICE *pSndDev );
  48.  
  49.  
  50. //-----------------------------------------------------------------------------
  51. //
  52. // IConfigDatabase
  53. //
  54. //
  55. class IConfigDatabase
  56. {
  57. public:
  58.  
  59.     //
  60.     // Create an instance of the interface
  61.     //
  62.     static IConfigDatabase*             Create();
  63.  
  64.     //
  65.     // Load the config information in the text file given.  See below for information
  66.     // on the format of the text file.  SystemMemory and VideoMemory are in MB.
  67.     // CPU Speed is in MHz
  68.     //
  69.     virtual bool                            Load( WCHAR* FileName,
  70.                                                   const SOUND_DEVICE& soundDevice,
  71.                                                   const D3DADAPTER_IDENTIFIER9& DDid,
  72.                                                   const D3DCAPS9&,
  73.                                                   DWORD SystemMemory,
  74.                                                   DWORD VideoMemory,
  75.                                                   DWORD CPUSpeed) = 0;
  76.  
  77.     //
  78.     // Release the object.  Call this when done with the interface.
  79.     //
  80.     virtual void                            Release() = 0;
  81.  
  82. #ifdef ICONFIGDATABASE_USE_STL
  83.     //
  84.     // Get a vector of the resulting property set.  The first member of the string
  85.     // pair is the name and the second is the value.
  86.     //
  87.     virtual const std::vector<StringPair>&  GetAggregateProperties() const = 0;
  88.     virtual const std::vector<StringPair>*  GetNamedProperties(const char* ) const = 0;
  89. #endif
  90.  
  91.     //
  92.     // The following provide non-STL access to the device property set.
  93.     //
  94.     virtual unsigned int                    GetDevicePropertyCount() const = 0;
  95.     virtual const char*                     GetDeviceProperty(unsigned int) const = 0;
  96.     virtual const char*                     GetDeviceValue(unsigned int) const = 0;
  97.  
  98.     //
  99.     // The following provide non-STL access to the requirements
  100.     //
  101.     virtual unsigned int                    GetRequirementsPropertyCount() const = 0;
  102.     virtual const char*                     GetRequirementsProperty(unsigned int) const = 0;
  103.     virtual const char*                     GetRequirementsValue(unsigned int) const = 0;
  104.  
  105.     //
  106.     // The graphics device and vendor strings as given by the config file.
  107.     //
  108.     virtual const char*                     GetGfxDeviceString() const = 0;
  109.     virtual const char*                     GetGfxVendorString() const = 0;
  110.  
  111.     //
  112.     // The sound device and vendor strings as given by the config file.
  113.     //
  114.     virtual const char*                     GetSoundDeviceString() const = 0;
  115.     virtual const char*                     GetSoundVendorString() const = 0;
  116.  
  117.     //
  118.     // If an error has occurred, more details can be found here.
  119.     //
  120.     virtual bool                            IsError() const = 0;
  121.     virtual const char*                     GetErrorString() const = 0;
  122.  
  123. };
  124.  
  125. //-------------------------------------------------------------------------------------
  126. // EXAMPLE USAGE
  127. //
  128. // IConfigDatabase* pCDB = IConfigDatabase::Create();
  129. // if (!pCDB->Load("config.txt", d3dAdId, d3dCaps, SysMem, VidMem))
  130. // {
  131. //   ... error ...
  132. // }
  133. //
  134. //  ... use properties ...
  135. //
  136. // pCDB->Release();
  137. //
  138.  
  139. //-------------------------------------------------------------------------------------
  140. //  SYNTAX OF CONFIG FILE
  141. //
  142. //
  143. // First section is a list of PropertySets.  A PropertySet is a set of name/value pairs.
  144. // Each set must end with a "Break" line.  PropertySets can refer to other property sets
  145. // that preceed it in the file.
  146. //
  147. // Second section is an ApplyToAll block that is processed on all cards.  It is typically
  148. // used to setup defaults based on caps.
  149. //
  150. // Next section is the vendor list.  This provides a way to make card specific changes.
  151. //
  152. // The program first searches for DisplayVendor = 0xXXXX (for display hardware) or
  153. // AudioVendor = 0xXXXX (for audio hardware) that matches the current card.
  154. // It then skips any other *Vendor = lines to skip over duplicate vendors for identical devices
  155. // Any properties found after the 'Vendor =' lines and before the first device ID will be properties
  156. // for all devices from that vendor.  This properties list must end with a break.
  157. //
  158. // The program will then search for a device ID that matches, the device ID is the first hex number on a line.
  159. // Any properties found after a device ID and before the next "break" will be returned.
  160. // Any device IDs found before the next break are ignored.  This allows multiple device IDs to
  161. // share a property list.
  162. //
  163. // Each list of device IDs may end with the unknown keyword.  Unrecognized devices will use the set found
  164. // here.
  165. //
  166. // The Vendor list may end with a "Vendor = unknown" section that functions much like the unknown device.
  167. //
  168. // Note on property lists --
  169. // If a property is found twice, or overrides a unknown property, only the last one specified will be returned.
  170. // Properties can consist of 'property=value'
  171. // Properties can consist of single keywords (like Disable1024*768)
  172. // Properties cannot start with numbers (they may be confused with devices otherwise)
  173. // Properties are case insensitive and are converted to lower case.
  174. // Values are also converted to lower case, unless surround by quotes. Values can only contain spaces inside quotes ie: "Bad Card"
  175. //
  176. // Other Logic:
  177. //
  178. // IF condition
  179. //  xxx
  180. //  xxx
  181. // ENDIF
  182. //
  183. // IF/ENDIF can only occur in any property set. They cannot surround multiple devices. IF/ENDIF can be nested.
  184. //
  185. // condition can be any of the following:
  186. //
  187. // ram = value                             (ie:  if ram > 64 )
  188. // videoram = value                        (ie:  if videoram < 16 )
  189. // SubSysID = value                        (ie:  if SubSysID = 2345 )
  190. // Revision = value                        (ie:  if Revision = 1 )
  191. // driver = value.value.value.value        (ie:  if driver = 4.1.25.1111 )
  192. // guid = hex-hex-hex-hex-hex              (ie:  if guid = D7B71F83-6340-11CF-4C73-0100A7C2C935 )
  193. // os = value                              (ie:  if os > win98 )
  194. //
  195. // Other conditions include all the DWORD memebers of the D3DCAPS8 structure.  For example,
  196. //
  197. // DevCaps & Flag
  198. //
  199. // You can use '=' '==' '<>' '!=' '>=' '<=' '>' '<' or '&' in comparissions
  200. // Value can be a decimal or hex number (starting with 0x)
  201. //
  202. // Ram is system memory
  203. // VideoRam is video memory
  204. // Driver is the driver version number
  205. // SubSysID is the driver subsystem ID number
  206. // Revision is the driver revision number
  207. // GUID is the single identified for hardware and driver this can only be compared as '=' '==' '!=' or '<>'
  208. // os is a value Win95=0, Win98=1, Win98SE=2, WinME=3, Win2K=4, WinXP=5
  209. //
  210.  
  211. #endif // __CONFIGDATABASE_H__
  212.